import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { SettingsService } from './settings.service';
import { CreateSettingsDto, BaseSettingsDto, UpdateSettingsDto, QuerySettingsDto, ListSettingsDto } from './dto/settings.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('防沉迷设置表，存储应用的使用时间限制设置')
@Controller('system/settings')
export class SettingsController {
  constructor(private readonly settingsService: SettingsService) {}

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-创建' })
  @ApiDataResponse(BaseSettingsDto)
  // @RequirePermission('system:settings:add')
  @Post()
  create(@Body() body: CreateSettingsDto) {
    return this.settingsService.create(body);
  }

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-列表' })
  @ApiDataResponse(ListSettingsDto, true, true)
  // @RequirePermission('system:settings:list')
  @Get('list')
  findAll(@Query() query: QuerySettingsDto) {
    return this.settingsService.findAll(query);
  }

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-详情' })
  @ApiDataResponse(BaseSettingsDto)
  // @RequirePermission('system:settings:query')
  @Get(':childId')
  findOne(@Param('childId') childId: number) {
    return this.settingsService.findOne(childId);
  }

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-详情' })
  @ApiDataResponse(BaseSettingsDto)
  // @RequirePermission('system:settings:query')
  @Get('check/:childId')
  check(@Param('childId') childId: number) {
    return this.settingsService.check(childId);
  }

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-修改' })
  @ApiDataResponse()
  // @RequirePermission('system:settings:edit')
  @Put()
  update(@Body() body: UpdateSettingsDto) {
    return this.settingsService.update(body);
  }

  @ApiOperation({ summary: '防沉迷设置表，存储应用的使用时间限制设置-删除' })
  @ApiDataResponse()
  // @RequirePermission('system:settings:remove')
  @Delete(':childId')
  remove(@Param('childId') childId: string) {
    const childIds = childId.split(',').map((id) => +id);
    return this.settingsService.remove(childIds);
  }
}
